﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrendingReader
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private void TsBtnGetStories_Click(object sender, EventArgs e)
        {
            var forms = this.MdiChildren;
            foreach (var form in forms)
            {
                if (form is V1.FrmGetStories)
                {
                    form.Activate();
                    return;
                }
                    
            }

            var frmGetStories = new V1.FrmGetStories();            
            frmGetStories.MdiParent = this;
            //frmGetStories.StartPosition = FormStartPosition.Manual;
            //int x = this.DesktopBounds.Left + (this.Width - frmGetStories.Width) / 2;
            //int y = this.DesktopBounds.Top + (this.Height - frmGetStories.Height) / 2;
            //frmGetStories.SetDesktopLocation(x, y);
            frmGetStories.Show();
        }

        private void TsBtnStoriesList_Click(object sender, EventArgs e)
        {
            var forms = this.MdiChildren;
            foreach (var form in forms)
            {
                if (form is FrmStoriesList)
                {
                    form.Activate();
                    return;
                }
            }

            var frmStoriesList = new FrmStoriesList();
            frmStoriesList.MdiParent = this;
            //frmStoriesList.StartPosition = FormStartPosition.Manual;
            //int x = this.DesktopBounds.Left + (this.Width - frmStoriesList.Width) / 2;
            //int y = this.DesktopBounds.Top + (this.Height - frmStoriesList.Height) / 2;
            //frmStoriesList.SetDesktopLocation(x, y);
            frmStoriesList.Show();
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            var forms = this.MdiChildren;
            if (forms.Length > 0)
            {
                if (MessageBox.Show("Vẫn đang có cửa sổ đang chạy, bạn có chắc muốn đóng chương trình không?", "Hey!",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    e.Cancel = true;
                    return;
                }

                foreach (var form in forms)
                {
                    form.Close();
                }
            }

            Application.ExitThread();
        }
    }
}
